<template>
      <div>
    <van-nav-bar
  title="登录账号"
  class="registerhedaer"
/>
    <van-form @submit="onSubmit">
      <van-cell-group inset>
        <van-field v-model="username" name="用户名" label="用户名" placeholder="用户名"
          :rules="[{ required: true, message: '请填写用户名' }]" />
        <van-field v-model="password" type="password" name="密码" label="密码" placeholder="密码"
          :rules="[{ required: true, message: '请填写密码' }]" />
      </van-cell-group>
      <div style="margin: 16px;">
        <van-button round block type="primary" native-type="submit">
          登录
        </van-button>
        <van-button round block type="default" @click="register">注册</van-button>
      </div>
    </van-form>

  </div>
  </template>
  
  <script setup>
  import { reactive, ref } from 'vue'
  import axiosInstance from './../axios/req'
  import { useRouter } from 'vue-router';
  import { showNotify } from 'vant';
  const router = useRouter();
  const username = ref('');
const password = ref('');
  /**
 * 登录事件
 * @param values 表单参数对象
 */
const onSubmit = (values) => {

console.log("登录");
 //发送请求提交表单
 axiosInstance.get('user?name='+username.value+'&password='+password.value,)
    .then(res => {
      console.log(res.data.data);
      router.push('/Main');
    })
    .catch(err => {
      console.log(err);
      const obj = JSON.parse(err.request.response);
      console.log(obj);
         // 危险通知
      showNotify({ type: 'danger', message: obj.message });

    })
};
/**
* 注册跳转页面事件
*/
const register = () => {
console.log("注册");
router.push('/register');
}
  
  </script>